
<?php echo form_open('transaction/search/',array('method' => 'get')); ?>

<div class="header1">Search Options</div>
<div id="options">
	<ul style="display: inline;">
		<li><input type="radio" name="search_type" id="transaction" value ="0"
		checked /> transaction's id</li>
		<li><input type="radio" name="search_type" id="barcode" value ="1"
		 /> item barcode</li>
		<li><input type="text" name="search" class="textboxSearch"
			value="<?php echo $search; ?>"
			placeholder="please enter the keyword" maxlength="30" /> <input
			type="submit" id="btn_submit" class="buttonSearch" value="search">
		</li>
	</ul>
</div>

<?php echo form_close(); ?>
<br />
<div class="titleStyle1">This Month Transaction Summary</div>
<br />
<?php 
if ($result == null || sizeof($result)==0){
	echo '<div class="information">';
	echo 'no transaction found.';
	echo '</div>';
}else{
?>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
         	['Branch', 'Revenue'],
          <?php 

          $temp = 0;
		foreach ($result as $trans){
			
      		echo '[\''.$trans->branch_name.'\',';
			if ($trans->transaction_profit > 0){ 
				echo $trans->transaction_profit.']';
			}else{
				echo '0]';
			}
			if ($temp < count($result)){
				echo ',';
			}
				
      	}          
         ?>
         
        ]);

        var options = {
          title: 'Transaction Summary'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));
        chart.draw(data, options);
      }
</script>
<div id="piechart" style="width: 900px; height: 500px;"></div>
	
	
<?php 
	echo '<div class="transTable">';
	echo '<table id="resultTable">';
	echo '<tr>';
	echo '<td>';
	echo 'Branch ID';
	echo '</td>';
	echo '<td>';
	echo 'Branch Name';
	echo '</td>';
	echo '<td>';
	echo 'Branch Location';
	echo '</td>';
	echo '<td>';
	echo 'Tel';
	echo '</td>';
	echo '<td>';
	echo 'Submitted Date';
	echo '</td>';
	echo '<td>';
	echo 'Total Profit';
	echo '</td>';
	echo '<td>';
	echo 'Transaction\'s Detail';
	echo '</td>';
	echo '<td>';
	echo 'Download';
	echo '</td>';
	echo '</tr>';
	foreach ($result as $trans){
		echo '<tr class="';	
		if( $trans->transaction_created_date ==null){
			echo 'disallowed';
		}else {
			echo 'allowed';
		}
		echo '">';
		echo '<td>';
		echo $trans->branch_id;
		echo '</td>';
		echo '<td>';
		echo $trans->branch_name;
		echo '</td>';
		echo '<td>';
		echo $trans->branch_location;
		echo '</td>';
		echo '<td>';
		echo $trans->branch_tel;
		echo '</td>';
		echo '<td>';
		if( $trans->transaction_created_date ==null){
			echo 'unknown';
		}else
			echo $trans->transaction_created_date;
		echo '</td>';
		echo '<td>';
		if( $trans->transaction_created_date ==null){
			echo 'unknown';
		}else
			echo $trans->transaction_profit;
		echo '</td>';
		echo '<td style="text-align:center;">';
		if( $trans->transaction_created_date ==null){
			echo 'not submitted';
		}else
		echo '<a href="transaction/view/'.$trans->transaction_id.'">view</a>';
		echo '</td>';
		echo '<td style="text-align:center;">';
		if( $trans->transaction_created_date ==null){
			echo 'not submitted';
		}else
			echo '<a class="downloadButton"  href="'.base_url().'uploads/transactions/'.$trans->transaction_file_location.'">download</a>';
		echo '</td>';
		echo '</tr>';
	}
	echo '</table>';
	echo '</div>';
}
?>
<script>
$('#resultTable').find('tr').click( function(){
	var item_id = $(this).find('td:first').text();
	if (item_id > 0 )
		window.location.replace('<?php echo site_url()?>' + '/branch/update/' + item_id);
});
</script>

<br />
<div class="titleStyle1">Top 20 Item</div>
<?php 
if ($result == null || sizeof($result)==0){
	echo '<div class="information">';
	echo 'no transaction found.';
	echo '</div>';
}else{
	echo '<div class="waitingTable">';
	echo '<table>';
	echo '<tr>';
	echo '<td>';
	echo 'Item Barcode';
	echo '</td>';
	echo '<td>';
	echo 'Item Name';
	echo '</td>';
	echo '<td>';
	echo 'Quantity Sold';
	echo '</td>';
	echo '<td>';
	echo 'Profit';
	echo '</td>';
	echo '</tr>';
	foreach ($topsale as $trans){
		echo '<tr>';
		echo '<td>';
		echo $trans->item_barcode;
		echo '</td>';
		echo '<td>';
		echo $trans->item_name;
		echo '</td>';
		echo '<td>';
		echo $trans->quantity;
		echo '</td>';
		echo '<td>';
		echo $trans->sum;
		echo '</td>';
		echo '</tr>';
	}
	echo '</table>';
	echo '</div>';
}
?>

